﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Visualizator.Physics
{
    /// <summary>
    /// El integrador Verlet que corre el algoritmo completamente
    /// en el CPU.
    /// </summary>
    public class CPUVerletIntegrator: IVerletIntegrator
    {
        public float[] PosX { get; set; }
        public float[] PosY { get; set; }
        public float[] PosZ { get; set; }

        public float[] PrevPosX { get; set; }
        public float[] PrevPosY { get; set; }
        public float[] PrevPosZ { get; set; }

        public int ParticleCount { get; set; }

        public void Integrate(float dt)
        {
            Debug.Assert(PosX.Length >= ParticleCount && PosY.Length >= ParticleCount && PosZ.Length >= ParticleCount);
            Debug.Assert(PrevPosX.Length >= ParticleCount && PrevPosY.Length >= ParticleCount && PrevPosZ.Length >= ParticleCount);

            for (int i = 0; i < ParticleCount; i++)
            {
                float auxX = PosX[i];
                float auxY = PosY[i];
                float auxZ = PosZ[i];

                PosX[i] = auxX + auxX - PrevPosX[i];
                PosY[i] = auxY + auxY - PrevPosY[i];
                PosZ[i] = auxZ + auxZ - PrevPosZ[i];

                PrevPosX[i] = auxX;
                PrevPosY[i] = auxY;
                PrevPosZ[i] = auxZ;
            }
            
        }

        public void Initialize() { }


    }
}
